﻿package com.winglish.as3.utils{	
	public class NumberUtil {
		public function NumberUtil() { }
		
		/**
		 * 1자리 숫자 2자리로 만들기.
		 * @param	num
		 * @return
		 */
		static public function itostr( num: int ): String{
			if ( num < 10 ) return "0" + num;
			else return "" + num;
		}
		
		/**
		 * 숫자에 콤마 넣기
		 * @param	number
		 * @param	pointUnderMax 콤마 단위
		 * @return
		 */
		static public function comma(number:Number, pointUnderMax:uint=0):String{
			if (number>Number.MAX_VALUE || number<-Number.MAX_VALUE) throw new Error('범위를 벗어났습니다.');

			var a:Array = [];
			var u:String  = (pointUnderMax && number%1) ? '.' + number.toString().split('.')[1].slice(0, pointUnderMax) : '';
			var s:String  = number>=0 ?  (number-number%1).toString() : (number%1 - number).toString();
			var sn:String = number>=0 ? '' : (Number(s)<1 && u=='') ? '':'-';

			for (var i:int=s.length; i>0; i-=3) {
				a.unshift( (i-3) < 0 ? s.slice(0, i) : s.slice(i-3, i) );
			}

			return sn + a.join(',') + u;
		}
		
		/**
		 * 숫자형인지 판단.
		 * @param	str
		 * @return
		 */
		static public function isNumber(str:String):Boolean {
			if (isNaN(Number(str))) return false;
			else return true;
		}
	}	
}
